package com.karaoke.android.data.domain

import java.util.*

/**
 * Created by Allen on 15/7/14.
 */
enum class Direction
{
    ASC, DESC;


    companion object
    {

        /**
         * Returns the [Direction] enum for the given [String] value.

         * @param value
         * *
         * @return
         * *
         * @throws IllegalArgumentException in case the given value cannot be parsed into an enum value.
         */
        fun fromString(value: String): Direction
        {

            try
            {
                return valueOf(value.toUpperCase(Locale.US))
            }
            catch (e: Exception)
            {
                throw IllegalArgumentException(String.format(
                        "Invalid value '%s' for orders given! Has to be either 'desc' or 'asc' (case insensitive).",
                        value),e)
            }

        }

        /**
         * Returns the [Direction] enum for the given [String] or null if it cannot be parsed into an enum
         * value.

         * @param value
         * *
         * @return
         */
        fun fromStringOrNull(value: String): Direction?
        {

            try
            {
                return fromString(value)
            }
            catch (e: IllegalArgumentException)
            {
                return null
            }

        }
    }
}
